package com.ruoyi.project.poem.audiorecom.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.audiorecom.domain.AudioRecom;
import com.ruoyi.project.poem.audiorecom.service.IAudioRecomService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 读诗推荐Controller
 * 
 * @author shixiangwen
 * @date 2022-07-15
 */
@Controller
@RequestMapping("/poem/audiorecom")
public class AudioRecomController extends BaseController
{
    private String prefix = "poem/audiorecom";

    @Autowired
    private IAudioRecomService audioRecomService;

    @RequiresPermissions("poem:audiorecom:view")
    @GetMapping()
    public String audiorecom()
    {
        return prefix + "/audiorecom";
    }

    /**
     * 查询读诗推荐列表
     */
    @RequiresPermissions("poem:audiorecom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AudioRecom audioRecom)
    {
        startPage();
        List<AudioRecom> list = audioRecomService.selectAudioRecomList(audioRecom);
        return getDataTable(list);
    }

    /**
     * 导出读诗推荐列表
     */
    @RequiresPermissions("poem:audiorecom:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AudioRecom audioRecom)
    {
        List<AudioRecom> list = audioRecomService.selectAudioRecomList(audioRecom);
        ExcelUtil<AudioRecom> util = new ExcelUtil<AudioRecom>(AudioRecom.class);
        return util.exportExcel(list, "audiorecom");
    }

    /**
     * 新增读诗推荐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存读诗推荐
     */
    @RequiresPermissions("poem:audiorecom:add")
    @Log(title = "读诗推荐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AudioRecom audioRecom)
    {
        return toAjax(audioRecomService.insertAudioRecom(audioRecom));
    }

    /**
     * 修改读诗推荐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AudioRecom audioRecom = audioRecomService.selectAudioRecomById(id);
        mmap.put("audioRecom", audioRecom);
        return prefix + "/edit";
    }

    /**
     * 修改保存读诗推荐
     */
    @RequiresPermissions("poem:audiorecom:edit")
    @Log(title = "读诗推荐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AudioRecom audioRecom)
    {
        return toAjax(audioRecomService.updateAudioRecom(audioRecom));
    }

    /**
     * 删除读诗推荐
     */
    @RequiresPermissions("poem:audiorecom:remove")
    @Log(title = "读诗推荐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(audioRecomService.deleteAudioRecomByIds(ids));
    }
}
